package org.dromara.pe.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.pe.domain.bo.AchievementBo;
import org.dromara.pe.domain.bo.StatisticBo;
import org.dromara.pe.domain.vo.AchievementVo;
import org.dromara.pe.domain.vo.StatisticForClassVo;
import org.dromara.pe.domain.vo.StatisticVo;
import org.dromara.pe.service.IAchievementService;
import org.dromara.pe.service.IStatisticService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 数据统计
 *
 * @author Lion Li
 * @date 2024-09-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pe/statistic")
public class StatisticController extends BaseController {

    private final IAchievementService achievementService;

    private final IStatisticService statisticService;

    /**
     * 体测成绩排行榜
     */
    @SaCheckPermission("pe:statistic:list")
    @GetMapping("/list")
    public TableDataInfo<AchievementVo> list(AchievementBo bo, PageQuery pageQuery) {
        return achievementService.queryPageList(bo, pageQuery);
    }

    @SaIgnore
    @GetMapping("/last/seven/data")
    public R<List<StatisticVo>> queryLastSevenDaysData(StatisticBo bo) {
        return R.ok(statisticService.queryLastSevenDaysData(bo));
    }
    @SaIgnore
    @GetMapping("/sex/ratio")
    public R<List<StatisticVo>> querySexRatio(StatisticBo bo) {
        return R.ok(statisticService.querySexRatio(bo));
    }
    @SaIgnore
    @GetMapping("/participation/rate/student")
    public R<List<StatisticForClassVo>> queryParticipationRateByStudent(StatisticBo bo) {
        return R.ok(statisticService.queryParticipationRateByStudent(bo));
    }
    @SaIgnore
    @GetMapping("/participation/rate/scope")
    public R<List<StatisticVo>> queryParticipationRateByScope(StatisticBo bo) {
        return R.ok(statisticService.queryParticipationRateByScope(bo));
    }
    @SaIgnore
    @GetMapping("/student/num")
    public R<Map<String,Long>> queryStudentNum(StatisticBo bo) {
        return R.ok(statisticService.queryStudentNum(bo));
    }
}
